# -*- coding: utf-8 -*-

# Define your item pipelines here
#Tencent.json
#class TencentPipeline(object):
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html

import json

class TencentPipeline(object):
    #作为类的初始化方法
    def __init__(self):
        #创建文件
        self.filename = open("Tencent.json", "w", encoding="utf-8")

    def process_item(self, item, spider):
        jsontext = json.dumps(dict(item),ensure_ascii=False) + "\n"

        self.filename.write(str(jsontext.encode("utf-8"), encoding="utf-8"))
        return item
    #结束时调用关闭爬虫方法
    def close_spider(self, spider):
        self.filename.close()





